package com.technology.education.ui.common.withdraw_detail

import android.widget.ImageView
import com.angcyo.dsladapter.dpi
import com.angcyo.dsladapter.dslItem
import com.technology.education.R
import com.technology.education.base.BaseRecyclerTopBarFragment
import com.technology.education.data.model.WithdrawOrderDetailModel
import com.technology.education.ext.getColor
import com.technology.education.ext.loadImage
import me.hgj.jetpackmvvm.ext.parseState

/**
 *@author:create by BZY
 *Date: 2022/2/28 17
 * 提现详情
 * type 0 为教师申请退回保证金,保证金金额固定不能修改
 * 1 教师积分提现
 * 2 学生积分提现
 * 3 推广人员余额提现
 * 4 教师时长提现
 * 5.学生积分兑换时长
 */
class WithDrawDetailFragment : BaseRecyclerTopBarFragment<WithDrawDetailViewModel>() {
    override fun initViews() {
        mViewModel.id = arguments?.getString("id") ?: ""
        mViewModel.type = arguments?.getInt("type") ?: 0
        setTitle("提现详情")
        recycler.setBackgroundColor(getColor(R.color.bg_activity_gray))
    }

    override fun lazyLoadData() {
        loading()
    }

    private fun setUI(detail: WithdrawOrderDetailModel) {
        renderAdapter {
            dslItem(R.layout.item_withdraw_detail_status) {
                itemBindOverride = { itemHolder, _, _, _ ->
                    itemTopInsert = 24 * dpi
                    itemDecorationColor = getColor(R.color.bg_activity_gray)
                    itemHolder.tv(R.id.tv_status_start)?.text = "发起提现"
                    itemHolder.tv(R.id.tv_date_start)?.text = detail.createTime
                    itemHolder.v<ImageView>(R.id.iv_status_start)?.isEnabled = true

                    itemHolder.tv(R.id.tv_status_check)?.text = "提现审核中"
                    itemHolder.tv(R.id.tv_date_check)?.text = ""
                    itemHolder.v<ImageView>(R.id.iv_status_check)?.isEnabled = true

                    itemHolder.tv(R.id.tv_status_done)?.apply {
                        text = if (detail.withdrawAuditState == "2") "审核失败" else "提现成功"
                    }
                    itemHolder.tv(R.id.tv_date_done)?.text = ""
                    itemHolder.v<ImageView>(R.id.iv_status_done)?.isEnabled =
                        detail.withdrawAuditState == "1" || detail.withdrawAuditState == "2"
                }
            }

            if (detail.alipayNo.isNullOrEmpty()) {
                dslItem(R.layout.item_withdraw_detail_wx) {
                    itemTopInsert = 16 * dpi
                    itemBindOverride = { itemHolder, _, _, _ ->
                        itemHolder.tv(R.id.tv_order_no)?.text = detail.id
                        itemHolder.tv(R.id.tv_money)?.text = "¥${detail.money}"
                        itemHolder.tv(R.id.tv_type)?.text = "微信"
                        itemHolder.v<ImageView>(R.id.iv_code)?.apply {
                            loadImage(detail.wechatPayCode,this)
                        }
                    }
                }
            } else {
                dslItem(R.layout.item_withdraw_detail_info) {
                    itemTopInsert = 16 * dpi
                    itemBindOverride = { itemHolder, _, _, _ ->
                        itemHolder.tv(R.id.tv_order_no)?.text = detail.id
                        itemHolder.tv(R.id.tv_money)?.text = "¥${detail.money}"
                        itemHolder.tv(R.id.tv_type)?.text = "支付宝"
                        itemHolder.tv(R.id.tv_account)?.text = detail.alipayNo
                        itemHolder.v<ImageView>(R.id.iv_code)?.apply {

                        }
                    }
                }
            }

        }
    }

    override fun createObserver() {
        mViewModel.result.observe(this) {
            parseState(it, onSuccess = { detail ->
                setUI(detail)
            })
        }
    }
}